package com.lottery.ruok.lottrey.fragment;

import android.os.Bundle;
import android.os.Handler;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.adapter.OrderPagerAdapter;
import com.lottery.ruok.lottrey.ui.ShapeIndicatorView;

import butterknife.BindView;
import butterknife.ButterKnife;
/*
* 投注订单的fragment
* */
public class LoginOrderMainFragment extends BaseFragment {
    @BindView(R.id.tabNavigate)
    TabLayout tabNavigate;
    @BindView(R.id.viewPager)
    ViewPager viewPager;
    @BindView(R.id.custom_indicator)
    ShapeIndicatorView customIndicator;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        View view = inflater.inflate(R.layout.login_order_fragment, null);

        ButterKnife.bind(this, view);

        init();

        return view;
    }

    private void init() {
        viewPager.setOffscreenPageLimit(4);
        OrderPagerAdapter orderPagerAdapter = new OrderPagerAdapter(getChildFragmentManager());
        viewPager.setAdapter(orderPagerAdapter);

        tabNavigate.setTabsFromPagerAdapter(orderPagerAdapter);
        //将TabLayout和ViewPager关联起来

        tabNavigate.setupWithViewPager(viewPager);

        customIndicator.setupWithTabLayout(tabNavigate);
        customIndicator.setupWithViewPager(viewPager);

        if(getArguments().getBoolean("from_buy", false)){
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    viewPager.setCurrentItem(2);
                }
            }, 100);
        }
    }
}